<!-- SCRIPT QUE RECARGA CONTENIDO DE UN DIV -->
<script type="text/javascript">
function ReloadDiv(div,data){

        var variable_post= data.toString();
        $(div).html(variable_post);

}
</script>


<div>
    <table id="customers">
        <thead>
            <th><?php echo "Hora" ?></th>
            <?php foreach ($gestdent_box_list as $gestdent_box): ?>
            <th><?php echo $gestdent_box->getNombre() ?></th>
            <?php endforeach; ?>
        </thead>

        <tbody>
            <?php foreach ($gestdent_hora_list as $gestdent_hora): ?>
            <tr>
                <td class="hora">
                    <?php echo $gestdent_hora->getDescripcion() ?>
                </td>
                <?php foreach ($gestdent_box_list as $gestdent_box): ?>
                <td class="box">
                    <?php echo ("<div id='" . $gestdent_hora->getId() . "_" . $gestdent_box->getId() . "'>") ?>
                    <?php echo ("</div>") ?>
                </td>
                <?php endforeach; ?>
            </tr>
            <?php endforeach; ?>
        </tbody>
    </table>
</div>

<div>
    <table id="customers2">
        <thead>
            <th><?php echo "Hora" ?></th>
            <?php foreach ($gestdent_box_list as $gestdent_box): ?>
            <th><?php echo $gestdent_box->getNombre() ?></th>
            <?php endforeach; ?>
        </thead>

        <tbody>
            <?php foreach ($gestdent_hora_list as $gestdent_hora): ?>
            <tr>
                <td class="hora">
                    <?php echo $gestdent_hora->getDescripcion() ?>
                </td>
                <?php foreach ($gestdent_box_list as $gestdent_box): ?>
                <td class="box">
                    <?php echo ("<div id='" . $gestdent_hora->getId() . "_" . $gestdent_box->getId() . "'>") ?>
                    <?php echo ("</div>") ?>
                </td>
                <?php endforeach; ?>
            </tr>
            <?php endforeach; ?>
        </tbody>
    </table>
</div>



<!-- RECORRIENDO LOS HORARIOS -->
<?php foreach ($gestdent_horario_list as $gestdent_horario): ?>

    <?php $MyIdBox = $gestdent_horario->getBoxId(); ?>
    <?php $MyIdDoctor = $gestdent_horario->getPersonalId(); ?>
    <?php $HorarioDetalles = $gestdent_horario->getDetalle(); ?>
    <?php $MostrarDoctor = true; ?>

    <?php foreach ($HorarioDetalles as $HorarioDetalle): ?>

        <?php $MyIdHora = $HorarioDetalle->getHoraId(); ?>
        <?php $DivHorario = $MyIdHora."_".$MyIdBox; ?>

        <?php $data = "<div class = 'boton' id='" . $MyIdHora . "_D_" . $MyIdDoctor . "'><button>Reservar</button>" ?>

        <?php if ($MostrarDoctor == true): ?>
            <?php $data = "<div id='" . $MyIdBox . "_DR_" . $MyIdDoctor . "' class='amarillito'>". $gestdent_horario->getGestdentPersonal() ."</div>".$data  ?>
            <?php $MostrarDoctor = false; ?>
        <?php endif; ?>

        <?php echo '<script language="javascript">ReloadDiv("#'.$DivHorario.'","'.$data.'")</script>' ?>

    <?php endforeach; ?>

<?php endforeach; ?>



<!-- CICLO QUE RECORRE LAS RESERVAS -->
<?php foreach ($gestdent_reserva_list as $gestdent_reserva): ?>

    <!-- SE OBTIENE DOCTOR -->
    <?php $IdDoctorReserva = $gestdent_reserva->getPersonal(); ?>

    <!-- SE OBTIENE HORA DE LA RESERVA -->
    <?php $IdHoraReserva = $gestdent_reserva->getHora(); ?>

    <!-- SE OBTIENE PACIENTE DE LA RESERVA -->
    <?php $IdPacienteReserva = $gestdent_reserva->getGestdentPaciente(); ?>

    <!-- SE OBTIENE EL COLOR CORRESPONDIENTE AL TIPO DE ASISTENCIA -->
    <?php $MyColor = $gestdent_reserva->getGestdentTipoAsistencia()->getColor(); ?>

    <!-- GENERA DIV DE LA RESERVA -->
    <?php $DivReserva = $IdHoraReserva."_D_".$IdDoctorReserva; ?>

    <!-- PREPARA DATOS DE LA RESERVA -->
    <?php $data2 = "<div id='" . $IdHoraReserva. "_R_" . $IdDoctorReserva . "' style='background-color:".$MyColor."'>". $gestdent_reserva->getGestdentPaciente()."</div>"?>

    <!-- CARGA DATOS PREPARADOS EN EL DIV DE LA RESERVA -->
    <?php echo '<script language="javascript">ReloadDiv("#'.$DivReserva.'","'.$data2.'")</script>' ?>

<!-- FIN CICLO QUE RECORRE LAS RESERVAS -->
<?php endforeach; ?>


<!-- MANEJA BOTON JQUERY -->
<script type="text/javascript">
    $(function() {
        $( "button, input:submit, a", ".boton" ).button();
        $( "a", ".demo" ).click(function() { return false; });
    });
</script>